package com.hui.config.yj;

import org.springframework.security.authentication.AuthenticationManager;
import org.springframework.security.config.annotation.SecurityConfigurerAdapter;
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
import org.springframework.security.web.DefaultSecurityFilterChain;
import org.springframework.stereotype.Component;

@Component
public class YjAuthenticationSecurityConfig extends SecurityConfigurerAdapter<DefaultSecurityFilterChain, HttpSecurity> {

    @Override
    public void configure(HttpSecurity http) throws Exception {
        //自定义SmsCodeAuthenticationFilter过滤器
//        YjAuthenticationFilter yjAuthenticationFilter = new YjAuthenticationFilter();
//        yjAuthenticationFilter.setAuthenticationManager(http.getSharedObject(AuthenticationManager.class));
//        yjAuthenticationFilter.setAuthenticationSuccessHandler(mobileLoginSuccessHandler);

        //设置自定义SmsCodeAuthenticationProvider的认证器userDetailsService
        YjAuthenticationProvider yjAuthenticationProvider = new YjAuthenticationProvider();
        //在UsernamePasswordAuthenticationFilter过滤前执行
        http
                .authenticationProvider(yjAuthenticationProvider)
                .httpBasic();
        //在UsernamePasswordAuthenticationFilter过滤前执行
//        http.authenticationProvider(yjAuthenticationProvider)
//                .addFilterAfter(yjAuthenticationFilter, UsernamePasswordAuthenticationFilter.class);
    }
}
